package main
import (
    "fmt"
    "encoding/json"
)
type Student struct {
	Id string `json:"id"`
	Name string `json:"name"`
	Age int `json:"age"`
	Gender string `json:"gender"`
}

type Class struct {
	Title string `json:"title"`
	Students []Student `json:"students"`
}

func main() {
	var class = Class{
		Title: "Go语言",
		Students: make([]Student, 0),
	}
	for i := 0; i < 10; i++ {
		var student = Student{
			Id: fmt.Sprintf("s%d", i),
			Name: fmt.Sprintf("学生%d", i),
			Age: i,
			Gender: "男",
		}
		class.Students = append(class.Students, student)
	}
	data, err := json.Marshal(class)
	if err != nil {
		fmt.Println("序列化失败：", err)
	} else {
		fmt.Println(string(data))
	}
}